package com.wn.quality.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.PageBean;
import com.wn.entity.Nonconformance;
import com.wn.quality.mapper.NonconformanceMapper;
import com.wn.quality.service.NonconformanceService;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wuqingting
 * @date 2022/10/19
 */
@Service
public class NonconformanceServiceImpl implements NonconformanceService {
    @Autowired
    private NonconformanceMapper nonconformanceMapper;

    @Override
    public void add(Nonconformance nonconformance) {
        nonconformanceMapper.add(nonconformance);
    }

    @Override
    public void update(Nonconformance nonconformance) {
        nonconformanceMapper.update(nonconformance);
    }

    @Override
    public void delete(int id) {
        nonconformanceMapper.delete(id);
    }

    @Override
    public Nonconformance getById(int id) {
        return nonconformanceMapper.getById(id);
    }

    @Override
    public PageBean<Nonconformance> getPageByCondition(Nonconformance nonconformance, int currPage, int pageSize) {
        Page<Object> page = PageHelper.startPage(currPage, pageSize);
        List<Nonconformance> nonconformanceList = nonconformanceMapper.getByCondition(nonconformance);
        PageBean<Nonconformance> pageBean = PageBeanUtil.getPageBean(nonconformanceList, page, currPage, pageSize);
        return pageBean;
    }

    @Override
    public List<Nonconformance> getAllByCondition(Nonconformance nonconformance) {
        return nonconformanceMapper.getByCondition(nonconformance);
    }
}
